/**
 * Copyright 2016 JustWayward Team
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hzf.booklibrary.ui.presenter;

import com.hzf.booklibrary.ReaderApplication;
import com.hzf.booklibrary.api.BookApi;
import com.hzf.booklibrary.base.RxPresenter;
import com.hzf.booklibrary.bean.Recommend;
import com.hzf.booklibrary.bean.book.Book;
import com.hzf.booklibrary.ui.contract.SearchContract;
import com.hzf.booklibrary.utils.LogUtils;

import java.util.List;

import javax.inject.Inject;

import rx.Observer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @author lfh.
 * @date 2016/8/6.
 */
public class SearchPresenter extends RxPresenter<SearchContract.View> implements SearchContract.Presenter<SearchContract.View> {

    private BookApi bookApi;

    @Inject
    public SearchPresenter(BookApi bookApi) {
        this.bookApi = bookApi;
    }

    @Override
    public void getSearchResultList(String page,String key) {
//        Subscription rxSubscription = bookApi.getSearchResult(page,key).subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<Recommend>() {
//                    @Override
//                    public void onNext(Recommend recommend) {
//                        List<Book> list = recommend.result.items;
//                        if (list != null&& mView != null) {
//                            mView.showSearchResultList(list);
//                        }
//                    }
//                    @Override
//                    public void onCompleted() {
//                        mView.complete();
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        LogUtils.e(e.toString());
//                        mView.showError();
//                        ReaderApplication.getsInstance().initIpAdress();//重新获取IP地址
//                    }
//                });
//        addSubscrebe(rxSubscription);
    }
}
